#include "MultiDnsResolver.hpp"
#include "Logger.hpp"

#include <iostream>
#include <string>

using namespace std;

void
Usage(char* arg)
{
    cout << "Usage : " << arg << " -[u] url" << endl;
    exit(-1);
}

int
main(int argc, char** argv)
{
    if (argc < 2) {
        Usage(argv[0]);
    }

    MultiDnsResolver dns_resolver;

    Logger* logger = new Logger;
    logger->Init(&cout);
    logger->SetColor(true);

    LOG_TIME(logger) << " started" << endl;
    string url;

    if (strcmp(argv[1], "-u") == 0) {
        LOG_INFO(logger) << argv[2] << " == " << dns_resolver.GetIP(argv[2]) << endl;
    } else {
        map<string, string> url_ip_map;
        while (getline(cin, url)) {
            url_ip_map[url] = "";
        }

        if (dns_resolver.GetIPList(url_ip_map) == 0) {
            map<string, string>::iterator it;
            for (it=url_ip_map.begin(); it!=url_ip_map.end(); ++it) {
                LOG_INFO(logger) << it->first << " == " << it->second << endl;
            }
        } else {
            LOG_INFO(logger) << "Faild!" << endl;
        }
    }
    
    LOG_TIME(logger) << " ended" << endl;
    delete logger;
    logger = NULL;
}

